﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace PhilipSupport.Controls
{
    public partial class PwdTextBox : TextBox
    {
        private Font font = new Font("微软雅黑", 11);
        private SolidBrush msgbrush = new SolidBrush(Color.FromArgb(255, 220, 220, 220));
        private SolidBrush textbrush = new SolidBrush(Color.Black);

        private bool pwd_visible = false;

        public string PlaceHolder
        {
            get;
            set;
        }

        public bool PwdVisible
        {
            get;set;
            //set
            //{
            //    if (value)
            //    {
            //        this.SetStyle(ControlStyles.UserPaint, false);
            //    }
            //    else
            //    {
            //        this.SetStyle(ControlStyles.UserPaint, true);
            //    }

            //    pwd_visible = value;
            //}

            //get
            //{
            //    return pwd_visible;
            //}
        }

        public PwdTextBox()
        {
            InitializeComponent();
            this.BorderStyle = BorderStyle.None;
            this.Font = new Font("微软雅黑", 12F);
            this.TextChanged += CustomTextbox_TextChanged;
        }

        private void CustomTextbox_TextChanged(object sender, EventArgs e)
        {
            if (this.Text.Length == 0)
            {
                this.SetStyle(ControlStyles.UserPaint, true);
            }
            else
            {
                this.SetStyle(ControlStyles.UserPaint, false);
            }
            this.Refresh();
        }

        protected override void OnPaint(PaintEventArgs pe)
        {
            if (!string.IsNullOrEmpty(PlaceHolder) && this.Text.Length == 0)
            {
                pe.Graphics.DrawString(PlaceHolder, font, msgbrush, 2, 0);
            }
            //else if (!PwdVisible)
            //{
            //    string cover = "";
            //    if (this.Text.Length > 0)
            //    {
            //        for (int i = 0; i < this.Text.Length; i++)
            //        {
            //            cover = cover + "*";
            //        }
            //    }
            //    pe.Graphics.DrawString(PlaceHolder, font, textbrush, 2, 0);
            //}
            base.OnPaint(pe);
        }
    }
}
